home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CUJ9208.ARJ / 1008117A < prev    next >
Text File  |  1992-06-04  |  5KB  |  209 lines

  1. 1: /************************************************************
  2. *      Program: RMENU Menu Interpreter
  3. *       Module: rmenu3.c
  4. *         Execute a Menu Item
  5. *      Written by: Leor Zolman, 7/91
  6. ************************************************************/
  7.  
  8. #include "cmenu.h"
  9. #include "rcmenu.h"
  10.  
  11. #if __STDC__
  12. #pragma hdrstop
  13. #endif
  14.  
  15. /************************************************************
  16.  * do_item():
  17.  * Perform the action associated with a particular item.
  18.  * Default path is supplied as "path":
  19.  ************************************************************/
  20.  
  21. int do_item(M2p, curr, path)
  22. MENU2 *M2p;
  23. int curr;
  24. char *path;
  25. {
  26.    ITEM *Ip = M2p -> Items[curr];
  27.    char newpath[MAX_PATH];
  28.    int i, j;
  29.  
  30.    strcpy(newpath, make_path(path, Ip -> path));
  31.  
  32.    switch (Ip -> acttyp)
  33.    {
  34.       case ACT_CMND:
  35.          do_cmnd(Ip, newpath);
  36.          break;
  37.  
  38.       case ACT_LMENU:
  39.          if (sub_menu(Ip->lmenunum, newpath) == EXITALL)
  40.             return EXITALL;
  41.          break;
  42.             
  43.       case ACT_EMENU:
  44.          if (do_emenu(Ip, newpath) == EXITALL)
  45.             return EXITALL;
  46.          break;
  47.    }
  48.    return OK;
  49. }
  50.  
  51.  
  52. /************************************************************
  53.  * show_item():
  54.  * Display the action associated with a particular item.
  55.  * Default path is supplied as "path":
  56.  ************************************************************/
  57.  
  58. Void show_item(M2p, curr, path)
  59. MENU2 *M2p;
  60. int curr;
  61. char *path;
  62. {
  63.    ITEM *Ip = M2p -> Items[curr];
  64.    char newpath[MAX_PATH];
  65.    int i, j;
  66.  
  67.    strcpy(newpath, make_path(path, Ip -> path));
  68.  
  69.    switch (Ip -> acttyp)
  70.    {
  71.       case ACT_CMND:
  72.          show_cmnd(Ip, newpath);
  73.          break;
  74.  
  75.       case ACT_LMENU:
  76.          put_msg(0, "This is a local menu. Press any key: ");
  77.          break;
  78.                   
  79.       case ACT_EMENU:
  80.          put_msg(0,
  81.           " Path: %s; Emenu spec: %s. Press any key to continue: ",
  82.                            newpath, Ip -> action);
  83.          break;
  84.    }
  85. /*  return OK; */
  86. }
  87.  
  88.  
  89. /************************************************************
  90.  * do_cmnd():
  91.  * Run a directly executable item.
  92.  ************************************************************/
  93.  
  94. Void do_cmnd(Ip, path)
  95. ITEM *Ip;
  96. char *path;
  97. {
  98.    char *cmd_line;
  99.    int retval;
  100.  
  101.    cmd_line = make_cmd(path, Ip -> action);
  102.  
  103.    if (Ip -> pre_clear == YES ||
  104.       (Ip -> pre_clear == DEFAULT && DEF_PRECLEAR == YES))
  105.          clear();
  106.  
  107.    move(0, 0);
  108.    refresh();
  109.  
  110.    if (debug)
  111.       put_msg(0, "About to exec: %s", cmd_line);
  112.  
  113.    pre_shell();                      /* set up for shell call    */
  114.    retval = system0(cmd_line);       /* make the shell call      */
  115.  
  116.    switch (Ip -> prompt)             /* decide whether to prompt */
  117.    {                                 /* or not after the command */
  118.       case NO:                       /* explicit no is clear     */
  119.          break;
  120.  
  121.       case DEFAULT:                  /* if unspecified, then...  */
  122.  
  123. #if (DEF_PROMPT == NO)               /* if default is NO,        */
  124.             break;                   /* then don't prompt        */
  125. #endif
  126.  
  127. #if (DEF_PROMPT == ON_ERROR)         /* if prompting on errors,  */
  128.          if (!retval)                /* but there wasn't any     */
  129.             break;                   /* error, then don't prompt */
  130. #endif
  131.                                      /* else fall through to YES */
  132.       case YES:
  133.          puts("\nPress RETURN to continue . . .");
  134.          (Void) getchar();
  135.    }
  136.                                      /* Upon return from shell,  */
  137.    post_shell();                     /* restore everything       */
  138. }
  139.  
  140.  
  141. /************************************************************
  142.  * show_cmnd():
  143.  * Show a directly executable action string.
  144.  ************************************************************/
  145.  
  146. Void show_cmnd(Ip, path)
  147. ITEM *Ip;
  148. char *path;
  149. {
  150.    char *cmd_line;
  151.    int retval;
  152.  
  153.    cmd_line = make_cmd(path, Ip -> action);
  154.  
  155.    put_msg(0, " Action: %s. Press a key to continue: ", cmd_line);
  156. }
  157.  
  158.  
  159. /**************************************************************
  160.  * do_emenu():
  161.  * Run an external menu specification.
  162.  **************************************************************/
  163.  
  164. int do_emenu(Ip, path)
  165. ITEM *Ip;
  166. char *path;
  167. {
  168.    char filename[MAX_PATH];
  169.    int retval;
  170.    
  171.    if (nestlev == MAX_NEST - 1)
  172.       return fatal("Menus nested too deeply (increase MAX_NEST)");
  173.  
  174.    strcpy(filename, make_path(path, Ip -> action));
  175.  
  176.    nestlev++;
  177.    retval = do_menu("", filename);
  178.    nestlev--;
  179.  
  180.    return retval;
  181. }
  182.  
  183.  
  184. /************************************************************
  185.  * pre_shell()
  186.  * Set tty mode for a shell call
  187.  * DOS only: save drive and path for later restoration
  188.  ************************************************************/
  189.  
  190.  
  191. Void pre_shell()
  192. {
  193.    push_path();
  194.    tty_shell();
  195. }
  196.  
  197.  
  198. /************************************************************
  199.  * post_shell()
  200.  * Set tty mode for curses
  201.  * DOS only: restore drive and path from before shell call
  202.  ************************************************************/
  203.  
  204. Void post_shell()
  205. {
  206.    pop_path();
  207.    tty_curses();
  208. }
  209.